import 'package:get/get.dart';
import 'package:xin_he/utils/xin_he_UI_constancs.dart';

import '../../../routes/xin_he_routes.dart';
import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import '../../../utils/xin_he_toast.dart';
import '../../shopping_car/xin_he_goods_payment/xin_he_payment_methods_model.dart';
import '../../shopping_car/xin_he_instant_pay/xin_he_instant_pay_view.dart';
import '../model/xin_he_adopt_tree_model_entity.dart';
import 'xin_he_adopt_payment_state.dart';

class XinHeAdoptPaymentLogic extends GetxController {
  final XinHeAdoptPaymentState state = XinHeAdoptPaymentState();
  List iconList = ['pay_method_alipay','pay_method_wechat','pay_method_redbag_small','pay_method_shopping','pay_method_mengya','pay_method_oil'];
  List titleList = ['余额','微信支付','消费金红包','购物金','未解冻云茶籽','茶油卡'];
  RxInt selectedIndex = 0.obs;
  RxList payMethodsList = [XinHePaymentMethodModel(),XinHePaymentMethodModel(),XinHePaymentMethodModel(),XinHePaymentMethodModel(),XinHePaymentMethodModel(),XinHePaymentMethodModel()].obs;

  Rx<XinHeAdoptTreeModelEntity> treeModel = XinHeAdoptTreeModelEntity().obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    treeModel.value = Get.arguments;
  }

  ///是否勾选
  changeSelectedStatus() {
    state.selected.value = !state.selected.value;
  }


  ///认养订单提交
  requestAdoptOrdersCommit() async {
    var userId =  await XinHeLocalStorage.get(XinHeStorage.userId);

    Map<String,dynamic> ss = {
      'userId':userId,
      'adoptedTreeId': 524827956560789504,
      'amount': treeModel.value.num,
      'buyerRemark':'',

    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/adoptedTreeOrder/saveAdoptedTreeOrder',params: ss,isPostAndwwwForm: true);
    if(!result.result) {
      XinHeToast.center(result.data['message']);
      return ;
    }

    if(  result.data['code'] == 0) {
      // Get.offNamed(XinHeRoutes.paySuccess);

      var orderId = result.data['data'];


      Get.bottomSheet(XinHeInstantPayPage(
        zoneType: 5,
        totalPrice:  getTotalPrice(),
        count: treeModel.value.num!,
        order: {'orderId': result.data['data']},
        scene: PayScene.fromAdoptOrder,),
        persistent: false,isScrollControlled: true,);



    }else {
      XinHeToast.center(result.data['message']);

    }


  }

  getTotalPrice() {

    return treeModel.value.num! * treeModel.value.price!;
  }

}
